package year2023.bitwise;

public class Code03_ExtractRightOne {

    public Code03_ExtractRightOne(int a){
        String str = TenToTwo(a);
        System.out.println(a + "的二进制为：" + str);

        //a = a & ((~a) +1);//提取最右侧的1
        a = a & (-a);

        str = TenToTwo(a);

        System.out.println(a + "最右侧的1为：" + str);
    }
    public String TenToTwo(int a){
        // 十进制转化为二进制
        int quotients = a;
        int remainders = 1;

        String str = "";

        //商和余数： quotients and remainders
        while(quotients != 0){

            remainders = quotients % 2;
            quotients = quotients / 2;

            str = remainders + str;
        }

        return str;

    }

    public static void main(String[] args) {
        int a = 10;
        Code03_ExtractRightOne code03_extractRightOne = new Code03_ExtractRightOne(a);

    }

}
